package org.lboot.jpa.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import java.util.Date;

/**
 * @author kindear
 * 自增主键ID的基础实体类
 */
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Schema(description = "基础实体类")
public abstract class LongBaseEntity {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Schema(description = "ID",name = "id")
    protected Long id;

    @CreatedBy
    @Schema(description = "记录创建者",name = "createdTime")
    @Column(name = "create_user_id")
    protected String createUserId;


    @LastModifiedBy
    @Column(name = "modify_user_id")
    @Schema(description = "记录修改者",name = "createdTime")
    protected String modifyUserId;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Schema(description = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    protected Date createdTime;

    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Schema(description = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    protected Date updatedTime;
}
